import PySimpleGUI as sg
import os

def nameAll(path, key, replace):
    filelist=os.listdir(path)
    for files in filelist:
        old_dir = os.path.join(path, files)
        new_file = files.replace(key, replace)
        new_dir = os.path.join(path, new_file)
        if files.find(key) > -1:
            os.rename(old_dir, new_dir)

layout = [[sg.Text('路径'), sg.InputText(size=(15,))],
          [sg.Text('关键字'), sg.InputText(size=(15,))],
          [sg.Text('替换字符'), sg.InputText(size=(15,))],
          [sg.Button('全部替换', key='submit')],
          [sg.Quit('退出', key='q')]]

window = sg.Window('批量文件关键字去除', layout, font='微软雅黑')

while True:
    event, value = window.Read()

    if event == 'submit':
        nameAll(value[0], value[1], value[2])
        sg.popup_ok('替换成功！')
    # 按钮关闭
    elif event == 'q':
        break
    # exit关闭
    if event == "Exit" or event == sg.WIN_CLOSED:
        break

window.close()